package model

type Share struct {
	Open      int64
	Close     int64
	High      int64
	Low       int64
	Ma5       int64
	Ma10      int64
	Ma20      int64
	Ma30      int64
	PreMa5    int64
	PreMa10   int64
	PreMa20   int64
	PreMa30   int64
	Timestamp int64
}

/**
设置单个share
 */
func (share *Share) SetShare(oneChartData interface{}, preShare Share) {
	if oneShare, ok := oneChartData.(map[string]interface{}); ok {
		for key, shareValue := range oneShare {
			switch key {
			case "open":
				share.Open = int64(shareValue.(float64) * 100)
				break
			case "close":
				share.Close = int64(shareValue.(float64) * 100)
				break
			case "high":
				share.High = int64(shareValue.(float64) * 100)
				break
			case "low":
				share.Low = int64(shareValue.(float64) * 100)
				break
			case "ma5":
				share.Ma5 = int64(shareValue.(float64) * 100)
				break
			case "ma10":
				share.Ma10 = int64(shareValue.(float64) * 100)
				break
			case "ma20":
				share.Ma20 = int64(shareValue.(float64) * 100)
				break
			case "ma30":
				share.Ma30 = int64(shareValue.(float64) * 100)
				break
			case "timestamp":
				share.Timestamp = int64(shareValue.(float64) / 1000)
				break
			default:
				break
			}
		}
		//没前一个
		if preShare.Ma5 <= 0 {
			share.PreMa5  = share.Ma5
			share.PreMa10 = share.Ma10
			share.PreMa20 = share.Ma20
			share.PreMa30 = share.Ma30
		} else {
			//有前一个
			share.PreMa5 = preShare.Ma5
			share.PreMa10 = preShare.Ma10
			share.PreMa20 = preShare.Ma20
			share.PreMa30 = preShare.Ma30
		}
	}
}


